package cn.leetcode;

import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;

public class Code169 {
    public int majorityElement(int[] nums) {
        int i = nums.length / 2;
        Map<Integer, Integer> map = new HashMap<>();
        for (int num : nums) {
            Integer integer = map.get(num);
            if (integer == null) {
                integer = 1;
                map.put(num, integer);
            } else {
                integer = integer + 1;
                map.put(num, integer);
            }
            if (integer > i) {
                return num;
            }
        }
        return -1;
    }

    public static void main(String[] args) throws UnknownHostException {
        int length = String.valueOf(System.currentTimeMillis()).length();
        InetAddress localHost = Inet4Address.getLocalHost();
        System.out.println(localHost.getHostAddress());
        System.out.println(length);
    }
}
